const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin")

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'js/[name].js',
        clean: true,
    },
    module: {
        rules: [
            // {
            //     test: /\.js$/,
            //     loader: './loader/test-loader.js',
            // },
            {
                test: /\.js$/,
                // 先执行test2，再执行test1。
                // use: ["./loader/demo/test1", "./loader/demo/test2"],
                // use: ["./loader/demo/test3"],
                // use: ["./loader/demo/test4", "./loader/demo/test5", "./loader/demo/test6"],
                use: ['./loader/clean-log-loader'],
            },
            {
                test: /.js$/,
                use: [{
                    loader: './loader/banner-loader',
                    options: {
                        author: "老王",
                    }
                }],
            },
            {
                test: /.js$/,
                loader: "./loader/babel-loader",
                options: {
                    presets: ["@babel/preset-env"],
                },
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                loader: "./loader/file-loader",
                type: 'javascript/auto', //阻止webpack默认处理图片资源，只使用'file-loader'
            },
            {
                test: /\.css/,
                // use: ["style-loader", "css-loader"],
                use: ["./loader/style-loader", "css-loader"],
            }
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, './public/index.html')
        }),
    ],
    mode: "development",
}